import type { CompanyInfoDto, CompanyProductInfoDto, EleSignInfoDto, PeriodInfoDto } from '@/api/company/types'
import TableRender, { type TableRenderColumnTypes } from '@/render/TableRender'
import type { AnyObject } from '@/types'
import { Component, Prop } from 'vue-facing-decorator'
import type { VxeColumnSlotTypes, VxeGridPropTypes, VxeTableDataRow } from 'vxe-table'
import toNative from '@/utils/toNative'
import type { FilterDto } from '@/render/FilterRender'

import { downloadFile } from '@/utils/util'
import type { WesureRecordDto } from '@/api/insurance/daily/types'
import { ElesignFlowStatusCnEnum, ElesignFlowStatusEnum, ElesignOperatorTypeCnEnum, getKeyToEnum } from '@/const/enum'
import { exportElesignContactRecord, getEleContractRecordList } from '@/api/company'
import type { TagType } from '@/api/types'
import { Button, Tag } from 'ant-design-vue'
import dayjs from 'dayjs'
import { getAccountRecord } from '@/api/insurance/elesign'
import type { AccountRecordDto } from '@/api/insurance/elesign/types'

@Component
export class ConsumeRecord extends TableRender {
    @Prop() eleSignInfo!: PeriodInfoDto
    @Prop() companyProductInfo!: CompanyInfoDto

    noTablePadding = true
    noFilterPadding = true
    filterTheme = 'light'

    curItem = {} as AccountRecordDto

    curMonthFirstDay = dayjs().startOf('month').format()
    curMonthLastDay = dayjs().endOf('month').format()

    filterConfig() {
        return {
            createTime: {
                name: '创建时间',
                element: 'rangePicker',
                params: {
                    valueFormat: 'YYYY-MM-DD'
                }
            },
        } as FilterDto
    }

    tableColumnConfigOld = () => [
        {
            field: 'amount',
            title: '消耗份量'
        },
        {
            field: 'createTime',
            title: '创建时间',
        },
    ] as TableRenderColumnTypes<AccountRecordDto>

    getData() {
        this.onPage({
            type: 'current',
            currentPage: 1
        })
    }

    async onExport() {
        const data = this.getFilters()
        const res = await exportElesignContactRecord({
            companyId: this.companyProductInfo.companyId,
            ...data
        })
        downloadFile(res)
    }

    onLoadData(page: number, size: number, filters: AnyObject) {
        if (!this.eleSignInfo.companyId) return []
        return getAccountRecord({
            companyId: this.companyProductInfo.companyId,
            companyName: this.companyProductInfo.companyName,
            pageNum: page,
            pageSize: size,
            ...filters,
            operateType: ElesignOperatorTypeCnEnum.消费
        })
    }

    renderRightBtns() {
        return (
            <>
                {/* <Button type="primary" onClick={this.onExport}>
                    导出列表
                </Button> */}
            </>
        )
    }

    render() {
        return super.render()
    }
}

export default toNative<
    { eleSignInfo: EleSignInfoDto; companyProductInfo: CompanyProductInfoDto },
    { refresh: () => void }
        >(ConsumeRecord)
  